<?php

namespace Apps\AppApi\Method\User;
use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Libs\PicUrl;
use Apps\Common\Models\UserMessage;


/**
 * 我的消息列表
 * @package Apps\AppApi\Method\User
 */
class MessageList extends BaseMethod
{
    public function run()
    {
        if(false == $this->verifyUserAuth()){
            return false;
        }

        $page = intval($this->getDataItem('page',1));

        $limit = $this->getConfig()->limit;
        $offset = ($page-1) * $limit;
        $userId = $this->getUserAuth()->userId;

        $data = UserMessage::query()
            ->columns([
                'message_id',
                'message_content',
                'message_state',
                'message_addtime',
                'message_link_type',
                'message_link_data',
            	'push_type',
            	'shop_id'
            ])
            ->where('user_id = :uid:', ['uid' => $userId])
            ->orderBy('message_id DESC')
            ->limit($limit, $offset)
            ->execute()
            ->toArray();
        $data = $data ? $data : [];
        $this->setResult($data);
    }
}
/*
'message_id' => 'message_id',
            'user_id' => 'user_id',
            'from_user_id' => 'from_id',
            'from_user_name' => 'from_user_name',
            'from_user_cover' => 'from_user_cover',
            'message_content' => 'message_content',
            'message_link_type' => 'message_link_type',
            'message_link_data' => 'message_link_data',
            'message_state' => 'message_state',
            'message_read_time' => 'message_read_time',
            'message_addtime' => 'message_addtime'
 */